using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Toenda.TFL.Base;
using Toenda.TFL.Data;
using Toenda.Rails.System;
using Toenda.Rails.DataContainer;

public partial class Privacy : System.Web.UI.Page {
	private AccountProvider ap = new AccountProvider();
	private Tools t = new Tools();

	/// <summary>
	/// Page_PreInit
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void Page_PreInit(object sender, EventArgs e) {
		try {
			XmlProvider xml = new XmlProvider(Server.MapPath("Configuration/Configuration.xml"));
			this.Page.Theme = xml.ReadTag("CurrentPageTheme");
		}
		catch(Exception ex) {
			string s = ex.Message;
			this.Page.Theme = "Default";
		}

		try {
			if(Session.Count > 0 && ap.CheckSessionExist(Session["Zappr"].ToString())) {
				Account acc = ap.GetAccountBySession(Session["Zappr"].ToString());
				this.Culture = acc.Language;
				this.UICulture = acc.Language.Substring(0, 2);
			}
			else {
				string[] langs = Request.UserLanguages;

				switch(langs[0].ToLower()) {
					case "de":
					case "de-de":
						this.Culture = "de-DE";
						break;

					case "en":
					case "en-us":
					case "en-gb":
						this.Culture = "en-US";
						break;

					default:
						this.Culture = "en-US";
						break;
				}

				this.UICulture = langs[0].Substring(0, 2);
			}
		}
		catch(Exception ex) {
			string s = ex.Message;
			this.Culture = "en-US";
			this.UICulture = "en";
		}
	}

	/// <summary>
	/// Page_Load
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void Page_Load(object sender, EventArgs e) {
		// read config
		XmlProvider xml = new XmlProvider(Server.MapPath("Configuration/Configuration.xml"));

		base.Title = xml.ReadTag("WebPageTitle");

		Control ctrl = Page.Master.FindControl("plcMasterVersion");
		ctrl.Controls.Add(new LiteralControl("<!--"));
		ctrl.Controls.Add(new LiteralControl("\n\tPowered by ASP.NET on Rails " + t.GetAssemblyVersion()));
		ctrl.Controls.Add(new LiteralControl("\n\tPowered by Toenda Foundation Library " + AssemblyInfo.Version));
		ctrl.Controls.Add(new LiteralControl("\n\tPowered by ASP.NET Ajax Extension"));
		ctrl.Controls.Add(new LiteralControl("\n\t-->"));

		plcHeader.Controls.Add(LoadControl("Controls/ctrl_header.ascx"));
		plcFooter.Controls.Add(LoadControl("Controls/ctrl_footer.ascx"));
	}
}
